import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    postcss: {
      plugins: [require("tailwindcss"), require("autoprefixer")]
    }
  },
  // publicPath: '/szy/v3/',
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  base:'https://dh.bjbayes.com/szy_zhensuo/dist',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host:'0.0.0.0',
    port:'5500',
    proxy: {
      '/renji': {
        target: 'https://www.bjbayes.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/renji/, '/renji') // 不可以省略rewrite
      },
      '/zhensuo': {
        target: 'https://www.bjbayes.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/zhensuo/, '/zhensuo') // 不可以省略rewrite
      },
      '/sizhen': {
        target: 'https://dh.bjbayes.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/sizhen/, '/sizhen') // 不可以省略rewrite
      }
    }
  },
  experimental: {
    renderBuiltUrl(filename, { hostId, hostType, type }) {
      if (type === 'public') {
        return 'https://dh.bjbayes.com/szy_zhensuo/dist/' + filename
      }
      else {
        return { relative: true }
      }
    }
  }
})
